﻿using System;
using System.Collections.Generic;

namespace InDepth2Demo.Chapter6
{
    public class ForeachDemo
    {
        //这里显示了不同的 yield return 语句，以强调可在迭代器方法中使用多个离散 yield return 语句这一事实。
        public IEnumerable<int> GetSingleDigitNumbers()
        {
            yield return 0;
            yield return 1;
            yield return 2;
            yield return 3;
            yield return 4;
            yield return 5;
            yield return 6;
            yield return 7;
            yield return 8;
            yield return 9;
        }

        public static void Call()
        {
            ForeachDemo foreachDemo = new ForeachDemo();
            IEnumerable<int> numbers = foreachDemo.GetSingleDigitNumbers();
            foreach (int digitNumber in numbers)
            {
                Console.WriteLine(digitNumber);
            }
        }
    }
}
